<?php htmlTemplate('index/header.tpl.php')?>
<script type="text/javascript">
function save(){
	var url = '<?php echo MVC_WWW_HOST?>user/address/do/save';
	var name = $.trim($("#name").val());
	var phone = $.trim($("#phone").val());
	var tel1 = $.trim($("#tel1").val());
	var tel2 = $.trim($("#tel2").val());
	var tel3 = $.trim($("#tel3").val());
	var areacode = $.trim($("#areacode").val());
	var province = $.trim($("#province").val());
	var city = $.trim($("#city").val());
	var area = $.trim($("#area").val());
	var street = $.trim($("#street").val());
	var isdefault = $("#isdefault").attr('checked');	 
    if(!name){
   		amsg('请填写收货人姓名'); 
   		$("#name").focus();
        return false;   
    }
    
    if(!province){
   		amsg('请填写省'); 
   		$("#province").focus();
        return false;   
    }
    if(!city){
   		amsg('请填写市'); 
   		$("#city").focus();
        return false;   
    }
    if(!area){
   		amsg('请填写区'); 
   		$("#area").focus();
        return false;   
    }
    if(!street){
   		amsg('请填写街道地址'); 
   		$("#street").focus();
        return false;   
    }
    if(!areacode){
   		amsg('请填邮政编码'); 
   		$("#areacode").focus();
        return false;   
    }
    if(!phone && !tel1){
   		amsg('电话号码、手机号码必填一项'); 
   		$("#phone").focus();
        return false;   
    }
    if(tel2 && !tel1){
    	amsg('请填写电话区号'); 
   		$("#tel1").focus();
        return false;  
    }
    if(tel1 && !tel2){
    	amsg('请填写电话号码'); 
   		$("#tel2").focus();
        return false;  
    }
    $.post(url,{'name':name,'phone':phone,'tel1':tel1,'tel2':tel2,'tel3':tel3,
        'areacode':areacode,'province':province,'city':city,'area':area,'street':street,'isdefault':isdefault
        },function(rs){
        amsg(rs);        
    })
}
function setdefault(id){
	var url = '<?php echo MVC_WWW_HOST;?>user/setdeaultaddr/id/'+id;
	$.get(url,function(rs){
		amsg(rs);
	})
}
</script>
<?php htmlTemplate('index/userleft.tpl.php')?>
        <div style="" class="lrtab">    
        <a href="<?php echo MVC_WWW_HOST?>user"   style="border-left: solid 1px #DFDFDF">基本信息</a>
        <a href="<?php echo MVC_WWW_HOST?>user/basicinfo" >个人资料</a>
        <a href="<?php echo MVC_WWW_HOST?>user/address" class="lrtabon" >收货地址</a>
        <a href="<?php echo MVC_WWW_HOST?>user/bank">银行信息</a>
        </div>
        <div class="clear"></div>
        <div style="padding-top:10px;width:100%;background: #f3f3f3;padding-bottom:10px;text-align: left;"><span style="font-size: 14px;font-weight:bold;padding-left:10px;">新增收货地址</span></div>
        <div>
            <form onsubmit="save();return false;">
                <table style="width: 100%">
            		<tr>
            			<td align="right">*收货人姓名：</td>
            			<td style="width:410px;"><input type="text" name="name" id="name" class="logintext" tabindex="1" ></td>
            			<td>&nbsp;</td>
            		</tr>
            		<tr>
            			<td align="right">*所在地区：</td>
            			<td colspan="2"><select id="province" name="province"></select>省 <select id="city" name="city"></select>市 <select id="area" name="area"></select>区
                        <script type="text/javascript">   
                        addressInit('province', 'city', 'area');
                        </script>
                        </td>
            			
            		</tr>
                    <tr>
                        <td align="right">*街道地址：</td>
                        <td valign="top"><textarea name="street" id="street" class="logintext3" tabindex="3" ></textarea>
                        </td>
                        <td class="logintips">不需要重复填写省/市/区</td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td align="right">*邮政编码：</td>
                        <td><input type="text" name="areacode" id="areacode" class="logintext2" tabindex="6"></td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td align="right">*手机号码：</td>
                        <td><input type="text" name="phone" id="phone" class="logintext2" tabindex="7">
                        <span class="logintips">无需加0，电话号码、手机号码必填一项</span>
                        </td>
                        <td>&nbsp;</td>
                        
                    </tr>
                    <tr>
                        <td align="right">*电话号码：</td>
                        <td>
                        <input type="text" name="tel1" id="tel1" class="logintext2" tabindex="8" style="width:50px;" > -
                        <input type="text" name="tel2" id="tel2" class="logintext2" tabindex="8"  > -
                        <input type="text" name="tel3" id="tel3" class="logintext2" tabindex="8" style="width:50px;" >
                        <span class="logintips">区号-电话号码-分机</span>
                        </td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td align="right">*设为默认：</td>
                        <td><input type="checkbox"" name="isdefault" id="isdefault" tabindex="9" ></td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td align="right">&nbsp;</td>
                        <td><input type="submit" value="保 存" class="regbtn" tabindex="8"></td>
                        <td>&nbsp;</td>
                    </tr>
                </table>
            </form>
        </div>
        <div style="padding-top:10px;width:100%;background: #f3f3f3;padding-bottom:10px;text-align: left;"><span style="font-size: 14px;font-weight:bold;padding-left:10px;">已经保存的有效地址</span></div>
        <table width="100%" cellpadding="3" cellspacing="1" class="ctable">
            <tr class="tr2">
                <th style="width:100px;" align="center">收货人</th>
                <th style="width:160px;" align="center">所在地区</th>
                <th style="width:160px;" align="center">街道地址</th>
                <th align="center">邮编</th>               
                <th align="center">手机/电话</th>               
                <th align="center">操作</th>
            </tr>
            <?php foreach ($rs as $k=>$v):?>
            <tr class="tr1">
                <td align="center" valign="middle"><?php echo $v['name'];?></td>
                <td align="left" valign="middle"><?php echo $v['province'];?> <?php echo $v['city'];?> <?php echo $v['area'];?></td>
                <td align="left"  valign="middle"><?php echo $v['street'];?></td>
                <td align="left" valign="middle"><?php echo $v['areacode'];?></td>               
                <td align="center" valign="middle"><?php echo $v['phone'];?><br><?php echo $v['tel1'];?>-<?php echo $v['tel2'];?>-<?php echo $v['tel3'];?></td>
                <td align="center" valign="middle"><?php if ($v['isdefault']){ echo '<span style="color:green;">默认地址</span>';}else{?><a href="javascript:setdefault('<?php echo $v['id']?>')">设为默认</a><?php }?> <a href="">修改</a> | <a href="">删除</a></td>
            </tr>
            <?php endforeach;?>
        </table>
<?php htmlTemplate('index/userfooter.tpl.php')?>
<?php htmlTemplate('index/footer.tpl.php')?>